package com.app.check;

import com.app.check.http.Cryptography;
import com.app.check.model.AuthorizeModel;
import com.app.check.task.GlobalModel;
import com.app.check.utils.Utils;
import Decoder.BASE64Encoder;
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;

public class BaseActivity extends FragmentActivity {

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
	}

	protected AuthorizeModel getAuthorizeModel() {
		AuthorizeModel model = new AuthorizeModel();
		{
			model.SessionId = Utils.ReadString(this, Utils.KEY_SESSIONID);
			model.UserId = Utils.ReadString(this, Utils.KEY_USERNAME);
			model.Password = Utils.ReadString(this, Utils.KEY_PASSWORD);
			if (!Utils.isEmpty(model.Password)) {
				model.Password = Cryptography.HashPassword(model.Password, "");
			}
		}
		return model;
	}

	protected AuthorizeModel getLoginAuthorizeModel() {
		AuthorizeModel model = new AuthorizeModel();
		{
			model.SessionId = "";
			model.UserId = Utils.ReadString(this, Utils.KEY_USERNAME);
			model.Password = Utils.ReadString(this, Utils.KEY_PASSWORD);
			if (!Utils.isEmpty(model.Password)) {
				model.Password = (new BASE64Encoder()).encode(model.Password
						.getBytes());
			}
		}
		return model;
	}

	protected GlobalModel getGlobalModel() {
		GlobalModel model = new GlobalModel();
		{
			model.ServerName = Utils.ReadString(this, Utils.KEY_SERVERNAME);
			model.ServerPort = Utils.ReadString(this, Utils.KEY_PORT);
		}
		return model;
	}
}
